/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制
*/
package co.yixiang.modules.shop.service.impl;

import co.yixiang.modules.shop.domain.ExpressArea;
import co.yixiang.common.service.impl.BaseServiceImpl;
import lombok.AllArgsConstructor;
import co.yixiang.dozer.service.IGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.modules.shop.service.ExpressAreaService;
import co.yixiang.modules.shop.service.dto.ExpressAreaDto;
import co.yixiang.modules.shop.service.dto.ExpressAreaQueryCriteria;
import co.yixiang.modules.shop.service.mapper.ExpressAreaMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;

/**
* @author chajiu
* @date 2021-04-25
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "ExpressArea")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class ExpressAreaServiceImpl extends BaseServiceImpl
<ExpressAreaMapper, ExpressArea> implements ExpressAreaService {

private final IGenerator generator;

@Override
//@Cacheable
public Map
<String, Object> queryAll(ExpressAreaQueryCriteria criteria, Pageable pageable) {
getPage(pageable);
PageInfo<ExpressArea> page = new PageInfo<>(queryAll(criteria));
Map
<String, Object> map = new LinkedHashMap<>(2);
map.put("content", generator.convert(page.getList(), ExpressAreaDto.class));
map.put("totalElements", page.getTotal());
return map;
}


@Override
//@Cacheable
public List<ExpressArea> queryAll(ExpressAreaQueryCriteria criteria){
return baseMapper.selectList(QueryHelpPlus.getPredicate(ExpressArea.class, criteria));
}


@Override
public void download(List
<ExpressAreaDto> all, HttpServletResponse response) throws IOException {
    List
    <Map
    <String
    , Object>> list = new ArrayList<>();
    for (ExpressAreaDto ExpressArea : all) {
    Map
    <String
    ,Object> map = new LinkedHashMap<>();
                map.put("运费方案细节id", ExpressArea.getDetailId());
                map.put("区域代码", ExpressArea.getAreaCode());
                map.put("区域类型 0省 1市", ExpressArea.getType());
                map.put("区域名称", ExpressArea.getAreaName());
    list.add(map);
    }
    FileUtil.downloadExcel(list, response);
    }
    }
